package com.wll.aop.controller;

import com.wll.aop.annotation.CustomNotEmpty;
import com.wll.aop.annotation.LogTrack;
import com.wll.aop.entity.UserEntity;
import com.wll.aop.service.UserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：wanglulu
 * @date ： 2021/11/16 15:37
 * @description：
 * @version: 1.0
 */
@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    UserSerivce userSerivce;

    @LogTrack("获取用户信息")
    @GetMapping("/user/info")
    public String getUser(@CustomNotEmpty String id, String name) {
        System.out.println("获取 user info 信息 " + id);
        return "success user";
    }

    @GetMapping("/user/list")
    public String getListUser() {
        System.out.println("获取 user list 信息 ");
        return "success list";
    }

    @LogTrack("add用户信息")
    @GetMapping("/add/user")
    public String addUser() {
        System.out.println("add user  信息 ");
        userSerivce.insertUser(getUser("add"));
        return "success add";
    }

    @LogTrack("update用户信息")
    @GetMapping("/update/user")
    public String updateUser() {
        System.out.println("update user list 信息 ");
        userSerivce.updateUser(getUser("update"));
        return "success update";
    }

    public static UserEntity getUser(String name){
        UserEntity userEntity = new UserEntity();
        userEntity.setUserName("lulu-->" + name);
        userEntity.setAge(20);
        userEntity.setAddress("西安");
        return userEntity;
    }

}
